package com.cs797.project;

import static android.provider.BaseColumns._ID;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class HotSpotData extends SQLiteOpenHelper {

    private static final String DATABASE_NAME = "HotSpotDB";
    private static final int DATABASE_VERSION = 1;
    
    public HotSpotData(Context context, CursorFactory factory) {
        super(context, DATABASE_NAME, factory, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // Base Station Info
        db.execSQL("CREATE TABLE BSInfo (" + 
                _ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
                "is_gsm INTEGER NOT NULL," +
                "bs_mcc TEXT NOT NULL," +
                "bs_mnc_sid TEXT NOT NULL," +
                "bs_lac_nid INTEGER NOT NULL," +
                "bs_cid_bid INTEGER NOT NULL," +
                "bs_latitude REAL NOT NULL," +
                "bs_longitude REAL NOT NULL);");
        
        // Mobile Station Info
        db.execSQL("CREATE TABLE MSInfo (" + 
                _ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
                "bs_id INTEGER NOT NULL," +
                "ms_latitude REAL NOT NULL," +
                "ms_longitude REAL NOT NULL," +
                "ms_signal_strength_dbm INTEGER NOT NULL);");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS BSInfo");
        db.execSQL("DROP TABLE IF EXISTS MSInfo");
        onCreate(db);
    }
    
    public void dropTables() {
        SQLiteDatabase db = this.getWritableDatabase();
        db.execSQL("DROP TABLE IF EXISTS BSInfo");
        db.execSQL("DROP TABLE IF EXISTS MSInfo");
        this.onCreate(db);
    }
}
